package com.dianjing.dianqun.service.dianpai;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dianjing.dianqun.common.base.CrudService;
import com.dianjing.dianqun.dao.dianpai.DianPaiCommentReplyMapper;
import com.dianjing.dianqun.dao.dianpai.DianPaiContentCommentMapper;
import com.dianjing.dianqun.model.DianPaiCommentReply;
import com.dianjing.dianqun.model.DianPaiContent;
import com.dianjing.dianqun.model.DianPaiContentComment;

/**
 * @date : 2017年10月24日
 * 
 * @author: baoyongtao
 * 
 * @see :
 * 
 */

@Service
@Transactional
public class DianPaiContentCommentService extends CrudService<DianPaiContentCommentMapper, DianPaiContentComment> {

	@Autowired
	private DianPaiContentCommentMapper commentMapper;
	@Autowired
	private DianPaiCommentReplyMapper commentReplyMapper;

	/**
	 * 查询3个评论和 回复自己能看到自己的評論
	 * 
	 * @param contentId
	 * @return
	 */
	public List<DianPaiContentComment> select3ByContentId(DianPaiContent content, Integer userId) {
		List<DianPaiContentComment> list = commentMapper.select3ByContentId(content.getContentId(), userId);
		for (DianPaiContentComment dianPaiContentComment : list) {
			// 封装3个小评论
			List<DianPaiCommentReply> replyList = commentReplyMapper .select3BycommentId(dianPaiContentComment.getCommentId(), userId);
			dianPaiContentComment.setReplyList(replyList);
		}
		return list;
	}

	/**
	 * 分页查询 点拍对应的评论自己可以看到自己都饿评论
	 * 
	 * @param contentId
	 * @param userId 
	 * @return
	 */

	public List<DianPaiContentComment> selectByContentId(Integer contentId, Integer userId) {
		List<DianPaiContentComment> list = commentMapper.selectByContentId(contentId,userId);
		for (DianPaiContentComment dianPaiContentComment : list) {
			List<DianPaiCommentReply> replyList = commentReplyMapper.findReplyByCommetId(dianPaiContentComment.getCommentId(),userId);
			dianPaiContentComment.setReplyList(replyList);
		}
		return list;
	}

	/**
	 * 临时开发
	 * 
	 * @return
	 */
	public List<DianPaiContentComment> findAllComment() {
		return commentMapper.findAllComment();
	}

	/**
	 * 临时开发
	 */
	public void chckedAll() {
		commentMapper.chckedAll();
	}

	/**
	 * 查询文章评论数量 自己可看到自己的
	 * @param id
	 * @param userId
	 * @return
	 */
	public Integer selectCountByConetnetId(Integer contentId, Integer userId) {
		return commentMapper.selectCountByConetnetId(contentId, userId);
	}
}
